package br.edu.fa7.receita.persistencia;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class SQLiteHelper extends SQLiteOpenHelper {
//  private String scriptCreate;
//  private String scriptDelete;
  
  private static final String SCRIPT_DB_DELETE_USUARIO =  "DROP TABLE IF EXISTS usuarios";
  private static final String SCRIPT_DB_DELETE_RECEITA = "DROP TABLE IF EXISTS receitas";
  
  	private static final String SCRIPT_DB_CREATE_USUARIO =
		    "create table usuarios (_id integer primary key autoincrement,nome text not null,email text not null,senha text not null,data_nasc text not null,sexo int not null); ";
		    
		
	private static final String SCRIPT_DB_CREATE_RECEITA = 
		"create table receitas (_id integer primary key autoincrement, titulo text not null, descricao text not null, urlimage text, usuarioid integer not null, FOREIGN KEY (usuarioid) REFERENCES usuarios (_id));";
		

  public SQLiteHelper(Context ctx, String nomeBd, int versaoBanco) {

      super(ctx, nomeBd, null, versaoBanco);
//      this.scriptCreate = scriptCreate;
//      this.scriptDelete = scriptDelete;
  }
  
  @Override
	public void onCreate(SQLiteDatabase db) {
	  db.execSQL(SCRIPT_DB_CREATE_USUARIO);
	  db.execSQL(SCRIPT_DB_CREATE_RECEITA);
	}
  
  @Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	  db.execSQL(SCRIPT_DB_DELETE_USUARIO);
	  db.execSQL(SCRIPT_DB_DELETE_RECEITA);
	  onCreate(db);
	}
}